package com.ahq.main;

import com.dalonedrau.jogl.engine.GameApplet;
import com.dalonedrau.jogl.engine.GlobalConsts;
import com.dalonedrau.jogl.engine.JOGLErrorHandler;
import com.dalonedrau.jogl.engine.Render;
import com.dalonedrau.jogl.engine.Sprite;
import com.dalonedrau.jogl.opengl.sprite.BasicTriangleSpriteObject;
import com.dalonedrau.jogl.opengl.sprite.SpriteBase;
import com.dalonedrau.jogl.opengl.ui.border.GuiBorder;

/**
 * A simple border, similar to those found in the early 90's SNES games.
 * @author Donald
 */
public final class H1HighlightBorder extends GuiBorder {
	/** the height of the selection border. */
	private int	height	= 0;
	/** Creates a new instance of {@link H1HighlightBorder}. */
	public H1HighlightBorder() {
		super.setInsets(
				0,
				GlobalConsts.INT_013,
				0,
				GlobalConsts.INT_013
				);

		SpriteBase sb = new BasicTriangleSpriteObject();
		sb.setX1(0);
		sb.setY1(0);
		sb.setX2(0);
		sb.setY2(10f);
		sb.setX3(10f);
		sb.setY3(5f);
		sb.setRed(0.8078f);
		sb.setGreen(0.12549f);
		sb.setBlue(0.16078f);
		super.setSprite(sb);
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void prepareForRendering() throws Exception {
		Render.getInstance().registerEntity(super.getSprite());
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void setPosition(final double x, final double y, final double z) {
		super.setPosition(x, y, z);
		try {
			Sprite.getInstance().computeFullStats(super.getSprite());
		} catch (Exception ex) {
			JOGLErrorHandler.getInstance().fatalError(ex);
		}
		double sy =
				y + (height - super.getSprite().getHeight())
						* GlobalConsts.DIV_2;
		super.getSprite().setPosition(
				x,
				sy,
				z
				);
		super.getSprite().clearFloatStore();
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void setPreferredSize(final int w, final int h) {
		super.setPreferredSize(w, h);
		// position the
		height = h;
		super.getSprite().clearFloatStore();
	}
}
